package Lab12;

import java.io.*;

import java.net.*;
import java.nio.charset.StandardCharsets;


public class Count2 {

    public static void main(String[] args) throws IOException {

        int HttpResult;

        URL url = new URL("https://www.douban.com/robots.txt");

        URLConnection urlconn = url.openConnection();
        urlconn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        urlconn.connect();

        HttpURLConnection httpconn = (HttpURLConnection) urlconn;

        HttpResult = httpconn.getResponseCode();

        if (HttpResult != HttpURLConnection.HTTP_OK) {

            System.out.print("无法连接到");

        }

        InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream(), StandardCharsets.UTF_8);

        BufferedReader br = new BufferedReader(isReader);

        String tem;

        int cntWord = 0;

        while ((tem = br.readLine()) != null) {


            String[] p = tem.split(" ");

            cntWord += p.length;


        }


        System.out.println(cntWord);
//        68

    }


}